package model;

import javax.faces.component.UIComponent;
import javax.faces.convert.FacesConverter;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value="distrConverter")
public class DistrConverter implements Converter{
// Init ---------------------------------------------------------------------------------------
    
    private static DistrDAO distrDAO = new DistrDAO();

    // Actions ------------------------------------------------------------------------------------
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        // Convert the unique String representation of Foo to the actual Foo object.
        return distrDAO.find(Long.parseLong(value));
    }
    
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        // Convert the Foo object to its unique String representation.
        return ((Distr) value).getId().toString();
    }

}
